<?php
    class V_Router {
        private static $_page;
        private static $_action;
        private static $_id;
        public static function activateModule () {
            // Назначение страницы и действия
            if (!isset($_GET['page']) or ($_GET['page']=="")) self::$_page="index";
            else self::$_page=$_GET['page'];
            if (!isset($_GET['action']) or ($_GET['action']=="")) self::$_action="index";
            else self::$_action=$_GET['action'];
            if (!isset($_GET['id']) or ($_GET['id']=="")) self::$_id="index";
            else self::$_id=$_GET['id'];
        }
        public static function getPage () {
            return self::$_page;
        }
        public static function getAction () {
            return self::$_action;
        }
        public static function getId () {
            return self::$_id;
        }
        public static function setPage ($page,$action='index',$id='') {
            if ($id=='') header('Location: /'.$page.'/'.$action.'.html');
            else header('Location: /'.$page.'/'.$action.'/id'.$id.'.html');
        }
        public static function url ($page,$action='index',$id='') {
            if ($id=='') return ('/'.$page.'/'.$action.'.html');
            else return ('/'.$page.'/'.$action.'/id'.$id.'.html');
        }
        public static function createPage ($page,$action,$path) {
            if (preg_match("/[[:lower:]]+/i",$page) and preg_match("/[[:lower:]]+/i",$action)) {
                if (file_exists($path.$page.'.php')) {
                    require_once ($path.$page.'.php');
                    eval ('$page = new Page_'.$page.';');
                    if (method_exists($page, $action)) {
                        $page->$action();
                        return true;
                    }
                } else return false;
            } else return false;
        }
    }

